#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    // 添加子菜单

    QMenuBar* menubar = new QMenuBar();
    this->setMenuBar(menubar);

    // 创建菜单
    QMenu* menuParent = new QMenu("父菜单"); // 父菜单
    QMenu* menuChild = new QMenu("子菜单"); // 子菜单
    menubar->addMenu(menuParent);
    // 父菜单也添加子菜单
    menuParent->addMenu(menuChild);

    // 给子菜单添加菜单项
    QAction* action1 = new QAction("菜单项1");
    QAction* action2 = new QAction("菜单项2");
    QAction* action3 = new QAction("菜单项2");
    // 子菜单添加菜单项
    menuChild->addAction(action1);
    menuChild->addAction(action2);
    menuChild->addAction(action3);

}

MainWindow::~MainWindow()
{
    delete ui;
}

